package com.scu.qingshi.config.cummunity;

import com.scu.qingshi.config.yaml.YamlPropertySourceFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 社团配置
 * @author qingshi
 */
@Configuration
@ConfigurationProperties(prefix = "list")
@PropertySource(value = {"classpath:/conf/community/community.yml"}, factory = YamlPropertySourceFactory.class)
public class CommunityFactory {

    private static List<CommunityConfig> community = new ArrayList<>();

    public static CommunityConfig getCommunity(String openId){
        return community.stream().filter(communityConfig -> Objects.equals(communityConfig.getOpenId(),openId))
                .findAny().orElse(null);
    }

    public void setCommunity(List<CommunityConfig> community){
        CommunityFactory.community = community;
    }

}
